import java.util.Arrays;

public class BasketWithApples {
  public int removeExcess( int[] apples ) {
    Arrays.sort( apples );
    int numberLeft = 0;

    for( int i = 0; i < apples.length; i++ ) {
      if( apples[i]*(apples.length-i) > numberLeft )
        numberLeft = apples[i]*(apples.length-i);
    }
    return numberLeft;
  }
}